package com.last.controller;

import com.last.config.UploadPic;
import com.last.entity.*;
import com.last.service.impl.IRoomInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/room")
// @CrossOrigin
public class RoomInfoController {
    @Autowired
    private IRoomInfoService iRoomInfoService;
    @Autowired
    private UploadPic uploadPic;
    @PostMapping("/search")
    public PageResult<RoomInfo> search(@RequestBody PageDTO<RoomInfo> pageDTO){
        return iRoomInfoService.search(pageDTO);
    }

    @PostMapping("/add")
    public Result addGoodsAndSku(@RequestBody RoomInfo roomInfo){
        return iRoomInfoService.add(roomInfo);
    }
    @GetMapping("/undercarriage")
    public Result undercarriage(Integer roomId){
            return iRoomInfoService.undercarriage(roomId,2);
    }
    @PostMapping("/upload")
    public String uploadPic(MultipartFile file){
        return uploadPic.upload(file);
    }

    @RequestMapping("/roomDetail")
    public RoomInfo getRoomInfoDetail(Integer roomId){
        RoomInfo roomInfoByRoomId = iRoomInfoService.getRoomInfoByRoomId(roomId);
        return roomInfoByRoomId;
    }
    @RequestMapping("/getAllCity")
    public List<City> getAllCity(){
        List<City> allCity = iRoomInfoService.getAllCity();
        return allCity;
    }

    @RequestMapping("/roomList")
    public List<RoomInfo> getHosingDetail(Integer homeId){
        List<RoomInfo> houseDetailInfo = iRoomInfoService.getHouseDetailInfo(homeId);
        return houseDetailInfo;
    }

}
